//
//  EPMtabBar.m
//  WeiBoByOC
//
//  Created by 马继鵬 on 17/3/19.
//  Copyright © 2017年 7TH. All rights reserved.
//

#import "EPMtabBar.h"

@interface EPMtabBar()
@property (weak,nonatomic) UIButton* plusBtn;
@end
@implementation EPMtabBar
- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame])
    {
        [self setupUI];
    }
    return self ;
}



#pragma
#pragma-设置UI
- (void)setupUI{
    
    UIButton* plusBtn = [[UIButton alloc]init];
    _plusBtn = plusBtn;
    [self addSubview:plusBtn];
    [plusBtn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add" ]forState:UIControlStateNormal];
    [plusBtn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"] forState:UIControlStateHighlighted];
    
    [plusBtn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
    [plusBtn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button_highlighted"] forState:UIControlStateHighlighted];
    
    
    [plusBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
   
}

#pragma
#pragma-点击方法实现
- (void)btnClick:(UIButton*)sender
{
    if (self.btnClickkBlock)
    {
        self.btnClickkBlock();
    }
}

- (void)layoutSubviews{
    [super  layoutSubviews];
    CGFloat width = self.bounds.size.width/5;
    CGFloat height = self.bounds.size.height;
    int index = 0;
    for (UIView* subView in self.subviews)
    {
        if ( [subView isKindOfClass:NSClassFromString(@"UITabBarButton")])
        {
            subView.frame = CGRectMake(index * width, 0,width , height);
            index += (index == 1 ? 2 : 1);
        }
    }
    _plusBtn.frame = CGRectMake(self.bounds.size.width/5 * 2, 0, self.bounds.size.width/5,self.bounds.size.height);
    
}

@end
